package com.szcinda.service.dto.analysis;

import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

@Data
public class ZadOrderYearCountDto implements Serializable {

    // 全年soc、coc、租箱统计
    private SoccocCountDto soccocCountDto = new SoccocCountDto();

    // 每月的线路平均时效
    private List<LineAgeDto> lineAgeList = new ArrayList<>();
    // 报关方式
    private List<OrderCountDto> bgList = new ArrayList<>();
    // 出境口岸
    private List<OrderCountDto> kaList = new ArrayList<>();
    // 货物品类
    private List<OrderCountDto> plList = new ArrayList<>();
    // 租箱点统计
    private List<OrderCountDto> zxdList = new ArrayList<>();
    // 归还状态
    private List<OrderCountDto> returnList = new ArrayList<>();
    // 相同起始站，不同目的站的订单数量
    private List<StartPlaceCountDto> sameStartPlaceList = new ArrayList<>();

    public void calculateLineAge() {
        // 排序
        lineAgeList.sort(Comparator.comparing(LineAgeDto::getMonth));
        for (LineAgeDto lineAgeDto : lineAgeList) {
            if (lineAgeDto.getCount() == 0) {
                continue;
            }
            lineAgeDto.setRatio(new BigDecimal(lineAgeDto.getAge()).divide(new BigDecimal(lineAgeDto.getCount()), 2, RoundingMode.HALF_UP).longValue());
        }
    }
}
